
def funcTest():
    print("This is funCTest")


if __name__ == "__main__":
    print("This is a Machine Learning Pro")
    arrayTest = [1,54,8,65,48,2,8,45,84,2,1,22,46,18,3,7,9]
    print(arrayTest)
    

#快速排序
#region 快速排序
#def QuickSort(arr,start,end):
#    #测试用输出
#    print(start,end)

#    # 结束循环条件
#    if start>=end:
#        return
    
#    #保存初始值
#    oldStart = start;
#    oldEnd = end;
#    #选择首项为比较用的值
#    temp = arr[start];

#    #一次快速排序
#    while (start<end):

#        #从后往前找比temp小的值与start交换位置
#        while(start<end):
#            #print(start,end)
#            if arr[end]<temp :
#                arr[start] = arr[end]
#                arr[end] = temp
#                break
#            else:
#                end=end-1
#        #从start往后找找到一个比temp大的值与end交换
#        while(start<end):
#            if arr[start]>temp :
#                arr[end] = arr[start]
#                arr[start] = temp
#                break
#            else:
#                start = start + 1
    

#    QuickSort(arr,oldStart,start-1);
#    QuickSort(arr,end+1,oldEnd);
#    return

###快排测试案例
#QuickSort(arrayTest,0,len(arrayTest)-1)
#print(arrayTest)

#endregion

#希尔排序
#region 希尔排序
import math

#def ShellSort(arr):
#    #设定初始间隔
#    arrLen = len(arr)
#    gap =  math.floor(arrLen/2)
    
#    while(gap>0):
        
#        i=0
#        while(i<gap):
#            current = i+gap
#            while(current<arrLen):
#                j=current - gap
#                while(j>=i and arr[current]<arr[j]):
#                    temp = arr[current]
#                    arr[current] = arr[j]
#                    arr[j] = temp
#                    j=j-gap
                
#                current=current+gap
            
#            i=i+1

#        #每一轮希尔排序完之后将间隔减半
#        gap = math.floor(gap/2)

print(__name__)
#ShellSort(arrayTest)
#print(arrayTest)

#endregion

#堆排序
def HeapSort(arr):
    startPos = math.floor((len(arr)-1)/2)
    arrMax=len(arr)-1
    while(startPos>=0):
        AdjHeap(arr,startPos,arrMax)
        startPos=startPos-1

    while(arrMax>0):
        temp=arr[arrMax]
        arr[arrMax]=arr[0]
        arr[0]=temp
        arrMax=arrMax-1
        AdjHeap(arr,0,arrMax)


#调整以pos为根节点的子树为大顶堆
def AdjHeap(arr,pos,end):
    print(pos)
    arrMax=end

    leftChildPos = pos*2+1
    rightChildPos = pos*2+2
    maxPos=pos
    if leftChildPos<=arrMax:
        if arr[leftChildPos]>arr[maxPos] :
            maxPos=leftChildPos
    if rightChildPos<=arrMax:
        if arr[rightChildPos]>arr[maxPos]:
            maxPos=rightChildPos

    if pos==maxPos:
        return
    else:
        temp=arr[pos]
        arr[pos]=arr[maxPos]
        arr[maxPos]=temp
        AdjHeap(arr,maxPos,end)

if __name__ == "__main__":
    #HeapSort(arrayTest)
    print(arrayTest)












